<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="cn.jhc.dao.NewsDAO"%>
<%@page import="cn.jhc.bean.NewsBean"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/houtai.css"></link>
<script type="text/javascript">
function MM_popupMsg(msg) {
     alert(msg);
}
</script>
<title>社团管理平台</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
	%>
	<div id="wrapper">
		<jsp:include page="./houtai_header.jsp"></jsp:include>
		<div id="left">
			<a href="houtai_news.jsp">新闻发布</a> <a href="houtai_index.jsp">公告发布</a>
			<a href="houtai_index.jsp">论坛信息</a>
		</div>
		<div id="right">
			<div id="right_top">
				<a>所在位置： 信息发布>新闻发布</a>
			</div>
			<%
				ArrayList<NewsBean> list = new ArrayList<NewsBean>();
				NewsDAO dao = new NewsDAO();
				dao.setCon(ConnectionFactory.getConnection());
				list = dao.getAllNews(CurrentPage);
				request.setAttribute("news", list);
			%>
			<%
				NewsDAO dao2 = new NewsDAO();
				dao2.setCon(ConnectionFactory.getConnection());
				intPageCount = dao2.getCount();
				if (CurrentPage > intPageCount)
					CurrentPage = intPageCount;
			%>
			<div id="right_news">
				<table width="100%">
					<tr>
						<th height="25">标题</th>
						<th>时间</th>
						<th>发表</th>
						<th>操作</th>
					</tr>
					<c:forEach items="${requestScope.news}" var="news">
						<tr>
							<td width="70%" height="25"><a
								href="newscontext.jsp?id=${news.id}">${news.title}</a></td>
							<td><div align="center">${news.date}</div></td>
							<td><div align="center">${news.name}</div></td>
							<td><div align="center"><a href="./deletenews.do?id=${news.id }" onclick="MM_popupMsg('删除成功！')">删除</a></div></td>
						</tr>
					</c:forEach>
				</table>
				<div align="right">
					<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
					</a> <a href="houtai_news.jsp?page=<%=1%>">首页</a>
					<%
						if (CurrentPage > 1) {
					%>
					<a href="houtai_news.jsp?page=<%=CurrentPage - 1%>">上一页</a>
					<%
						} else {
					%>
					上一页
					<%
						}
					%>
					<%
						if (CurrentPage >= intPageCount) {
					%>
					下一页
					<%
						} else {
					%>
					<a href="houtai_news.jsp?page=<%=CurrentPage + 1%>">下一页</a>
					<%
						}
					%>
					<a href="houtai_news.jsp?page=<%=intPageCount%>">末页</a>
				</div>
				<div id="button">
					<form method="post" action="./houtai_addnews.jsp">
						<input type="submit" value="点此发布新闻"></input>
					</form>
				</div>
			</div>
		</div>
	</div>
</body>
</html>